//
//  WSGMeViewController.m
//  oneDollar
//
//  Created by Laki on 16/6/15.
//  Copyright © 2016年 com.Laki.corder. All rights reserved.
//

#import "WSGMeViewController.h"

#import "WSGLoginRegisterViewController.h"
#import "WSGNavigationController.h"

#import "UIBarButtonItem+Item.h"

@interface WSGMeViewController ()
/** 登录按钮*/
@property (weak, nonatomic) IBOutlet UIButton *loginBtn;

@end

@implementation WSGMeViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    // 设置按钮背景图片不被拉伸
    [self setButtonImage];
    
    // 设置导航栏右侧按钮
//    [self setBarBtnItem];
}

- (void)setBarBtnItem{
    UIImage *image = [UIImage imageNamed:@"HYGMyPageSetting"];
    UIBarButtonItem *itemRight = [UIBarButtonItem itemImage:image withHighImage:nil addTarget:nil action:nil];
    UIBarButtonItem *itemLeft = [UIBarButtonItem itemImage:[UIImage imageNamed:@"Mylottery_FBMM_Barbutton"] withHighImage:nil addTarget:nil action:nil];
    self.navigationItem.rightBarButtonItems = @[itemLeft,itemRight];
}

#pragma mark --------------------
#pragma mark 登录
/*
 * 点击登录按钮
 */
- (IBAction)loginBtn:(id)sender {
    // 创建登录控制器
    WSGLoginRegisterViewController *login = [[WSGLoginRegisterViewController alloc] initWithNibName:NSStringFromClass([WSGLoginRegisterViewController class]) bundle:nil];

    // 创建导航栏左侧按钮
    UIBarButtonItem *barBtn = [[UIBarButtonItem alloc] initWithTitle:@"取消" style:UIBarButtonItemStylePlain target:self action:@selector(back)];
    
    // 设置左侧按钮设置颜色
    barBtn.tintColor = [UIColor whiteColor];
    // 设置导航栏标题
    login.navigationItem.title = @"登录";
    // 设置导航栏左侧按钮
    login.navigationItem.leftBarButtonItem = barBtn;
    
    // 包装导航控制器
    WSGNavigationController *nav = [[WSGNavigationController alloc] initWithRootViewController:login];
    
    // Modal跳转
    [self presentViewController:nav animated:YES completion:nil];
}

/*
 * 点击取消返回上一个控制器
 */
- (void)back{
    [self dismissViewControllerAnimated:YES completion:nil];
}

#pragma mark --------------------
#pragma mark 设置按钮背景图片不被拉伸
- (void)setButtonImage{
    // 获取当前背景图片
    UIImage *image = self.loginBtn.currentBackgroundImage;
    
    // 设置从中心点进行拉伸
    image = [image stretchableImageWithLeftCapWidth:image.size.width * 0.5 topCapHeight:image.size.height * 0.5];
    
    // 给按钮设置背景图片
    [self.loginBtn setBackgroundImage:image forState:UIControlStateNormal];
    
    // 创建高亮背景图片
    UIImage *highlightImage = [UIImage imageNamed:@"RedButtonPressed"];
    
    // 设置从中心点进行拉伸
    highlightImage = [highlightImage stretchableImageWithLeftCapWidth:highlightImage.size.width * 0.5 topCapHeight:highlightImage.size.height * 0.5];
    
    // 给按钮设置背景图片
    [self.loginBtn setBackgroundImage:highlightImage forState:UIControlStateHighlighted];
}
@end
